<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Thread 类</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="threaded.wait.html">« Threaded::wait</a></li>
      <li style="float: right;"><a href="thread.getcreatorid.html">Thread::getCreatorId »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.pthreads.html">pthreads</a></li>
    <li>Thread 类</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.thread" class="reference">

 <h1 class="title">Thread 类</h1>
 
  
 <div class="partintro"><p class="verinfo">(PECL pthreads &gt;= 2.0.0)</p>


  <div class="section" id="thread.intro">
   <h2 class="title">简介</h2>
   <p class="para">
  当调用 Thread 对象的 start 方法时，该对象的 run 方法中的代码将在独立线程中并行执行。
   </p>
   <p class="para">
  run 方法中的代码执行完毕之后，独立线程立即退出，并且等待合适的时机由创建者线程加入（join）。   
   </p>
   <div class="warning"><strong class="warning">警告</strong>
   <p class="para">
  依赖于引擎本身的机制检测何时加入线程可能引发非预期的行为，程序员应该尽可能的显式控制线程加入的时机。  
   </p>
   </div>
  </div>


  <div class="section" id="thread.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">Thread</strong>
     </span>
     
     <span class="ooclass">
      <span class="modifier">extends</span>
       <a href="class.threaded.html" class="classname">Threaded</a>
     </span>
     
     <span class="oointerface"><span class="modifier">implements</span> 
       <a href="class.countable.html" class="interfacename">Countable</a></span><span class="oointerface">,  <a href="class.traversable.html" class="interfacename">Traversable</a></span><span class="oointerface">,  <a href="class.arrayaccess.html" class="interfacename">ArrayAccess</a></span> {</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="thread.getcreatorid.html" class="methodname">getCreatorId</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="thread.getcurrentthread.html" class="methodname">getCurrentThread</a></span>(): <span class="type"><a href="class.thread.html" class="type Thread">Thread</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="thread.getcurrentthreadid.html" class="methodname">getCurrentThreadId</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="thread.getthreadid.html" class="methodname">getThreadId</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span><span class="methodname"><a href="thread.isjoined.html" class="methodname">isJoined</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span><span class="methodname"><a href="thread.isstarted.html" class="methodname">isStarted</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span><span class="methodname"><a href="thread.join.html" class="methodname">join</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="thread.start.html" class="methodname">start</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = ?</span></span>): <span class="type">bool</span></div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 继承的方法 */</div>
    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="threaded.chunk.html" class="methodname">Threaded::chunk</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$size</code></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$preserve</code></span>): <span class="type">array</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="threaded.count.html" class="methodname">Threaded::count</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="threaded.extend.html" class="methodname">Threaded::extend</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$class</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="thread.isrunning.html" class="methodname">Threaded::isRunning</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="threaded.isterminated.html" class="methodname">Threaded::isTerminated</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span><span class="methodname"><a href="threaded.merge.html" class="methodname">Threaded::merge</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$from</code></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$overwrite</code><span class="initializer"> = ?</span></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="threaded.notify.html" class="methodname">Threaded::notify</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="threaded.notifyone.html" class="methodname">Threaded::notifyOne</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="threaded.pop.html" class="methodname">Threaded::pop</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="threaded.run.html" class="methodname">Threaded::run</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="threaded.shift.html" class="methodname">Threaded::shift</a></span>(): <span class="type">boolean</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="threaded.synchronized.html" class="methodname">Threaded::synchronized</a></span>(<span class="methodparam"><span class="type"><a href="class.closure.html" class="type Closure">Closure</a></span> <code class="parameter">$block</code></span>, <span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$...</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="threaded.wait.html" class="methodname">Threaded::wait</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$timeout</code><span class="initializer"> = ?</span></span>): <span class="type">bool</span></div>


   }</div>


  </div>

 </div>

 













































































<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="thread.getcreatorid.html">Thread::getCreatorId</a> — 识别</li><li><a href="thread.getcurrentthread.html">Thread::getCurrentThread</a> — 识别</li><li><a href="thread.getcurrentthreadid.html">Thread::getCurrentThreadId</a> — 识别</li><li><a href="thread.getthreadid.html">Thread::getThreadId</a> — 识别</li><li><a href="thread.isjoined.html">Thread::isJoined</a> — 状态监测</li><li><a href="thread.isstarted.html">Thread::isStarted</a> — 状态检测</li><li><a href="thread.join.html">Thread::join</a> — 同步</li><li><a href="thread.start.html">Thread::start</a> — 执行</li></ul>
</div>
</div></div></body></html>